//地图工具
const GDMapTool = {
	init: () => {
		window._AMapSecurityConfig = {
			securityJsCode: localStorage.getItem('map.securityCode'),
		}
		var url = 'https://webapi.amap.com/maps?v=1.4.15&key=' + localStorage.getItem('map.securityKey');
		var jsapi = document.createElement('script');
		jsapi.charset = 'utf-8';
		jsapi.src = url;
		document.head.appendChild(jsapi);
	},
	createMap: (id, centerLng, centerLat) => {
		return new GDMap(id, centerLng, centerLat)
	},
}

class GDMap {
	constructor(id, centerLng, centerLat) {
		this.map = new AMap.Map(id, {
			resizeEnable: true, //是否监控地图容器尺寸变化
			zoom: 18, //初始化地图层级
			center: [centerLng, centerLat] //初始化地图中心点
		});
	}
	marker(lng, lat) {
		let marker = new AMap.Marker({
			icon: "http://a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-red.png",
			position: [lng, lat],
			offset: new AMap.Pixel(-13, -30)
		});
		marker.setMap(this.map);
		return marker;
	}
	destory() {
		this.map.destory()
	}
}